package com.bridge.bridge_login;

import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.CompoundButton;

import androidx.core.content.ContextCompat;

import com.bridge.bridge_login.databinding.AcRegisnBinding;
import com.bridge.common.base.BaseActivity;
import com.bridge.common.http.BaseBean;
import com.bridge.common.http.HttpUtils;
import com.bridge.common.http.RetrofitHelper;
import com.bridge.common.route.RouteUtils;
import com.bridge.common.utils.ToastshowUtils;

import java.util.HashMap;
import java.util.List;

import io.reactivex.Observable;
import okhttp3.ResponseBody;

/**
 * author : bridge.24
 * date   : 21.4.1018:17
 * desc   :
 */
public class RegisnActivity extends BaseActivity {
    private AcRegisnBinding binding ;
    private String content;
    private Context mContext ;

    @Override
    protected int layoutId() {
        return R.layout.ac_regisn;
    }

    @Override
    protected void initView() {
        binding = getBind() ;
        mContext = this ;
        ///
        content = "<font size='14' color='#4e8ce6'>《用户协议》</font>";
        binding.tvYhxy.setText(Html.fromHtml("我已阅读并同意" + content));
    }

    @Override
    protected void setListenner() {
        binding.checkView.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    binding.btnRegisn.setTextColor(ContextCompat.getColor(mContext ,R.color.white));
                    binding.btnRegisn.setBackground(ContextCompat.getDrawable(mContext ,R.drawable.btn_click_lv));
                    binding.btnRegisn.setEnabled(true);
                }else{
                    binding.btnRegisn.setTextColor(ContextCompat.getColor(mContext ,R.color.tv_normal));
                    binding.btnRegisn.setBackground(ContextCompat.getDrawable(mContext ,R.drawable.bg_click_gray));
                    binding.btnRegisn.setEnabled(false);
                }
            }
        });

        binding.btnRegisn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //注册
                String str_zh = binding.etZh.getText().toString();
                String str_nc = binding.etNc.getText().toString();
                String str_mm = binding.etMm.getText().toString();
                if(TextUtils.isEmpty(str_zh)){
                    ToastshowUtils.showToastSafe("账号不能为空");
                    return;
                }
                if(TextUtils.isEmpty(str_nc)){
                    ToastshowUtils.showToastSafe("昵称不能为空");
                    return;
                }
                if(TextUtils.isEmpty(str_mm)){
                    ToastshowUtils.showToastSafe("密码不能为空");
                    return;
                }
                turnToRegisn() ;
                finish();
            }
        });
        binding.titleView.setBackOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        }) ;
        binding.tvLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void turnToRegisn() {
        HashMap map = new HashMap();
        map.put("pageNo" ,1) ;
        map.put("pageSize" , 10) ;

        Observable<ResponseBody> call = RetrofitHelper.getApiService().xsZjList(getRqBody(map, null));
        doHttp(101, call, getString(R.string.loading), null);
    }

    @Override
    public void onSuccess(int requestCode, String result) {
        super.onSuccess(requestCode, result);
        switch (requestCode){
            case 101 :
                //这两行是你要转换  成的bean 对象   ， 返回的外层统一格式  在 BaseBean里 ，根据情况定制
                // code  已经在外部处理过了  ，这是 code == 1 情况下的  回调
//                XsCallBean anjianListBean = BaseBean.fromJson(result,XsCallBean.class);
//                List<XsCallBean.DataBean> dataList = anjianListBean.getData();
                break;
        }
    }

    @Override
    public void onFailure(int requestCode, String msg) {
        super.onFailure(requestCode, msg);
        //无网络情况 ，请求失败
    }
}
